package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.ScenicScore;
import com.ruoyi.system.mapper.ScenicScoreDao;
import com.ruoyi.system.service.ScenicScoreService;
import org.springframework.stereotype.Service;

/**
 * Auto created by codeAppend plugin
 */
@Service
public class ScenicScoreServiceImpl extends ServiceImpl<ScenicScoreDao, ScenicScore> implements ScenicScoreService {
    @Override
    public void addScenicScore(ScenicScore scenicScore) {
        ScenicScore ss = new ScenicScore();
        ss.setScenicId(scenicScore.getScenicId());
        ss.setScenicScore(scenicScore.getScenicScore());
        ss.setScenicNum(scenicScore.getScenicNum());
        baseMapper.insert(ss);
    }

    @Override
    public void updateScenicScore(ScenicScore scenicScore) {
        LambdaQueryWrapper<ScenicScore> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ScenicScore::getId, scenicScore.getId());
        ScenicScore ss = baseMapper.selectOne(lqw);
        if (ss == null){
            throw new RuntimeException("ScenicScore not found");
        }
        ss.setScenicId(scenicScore.getScenicId());
        ss.setScenicScore(scenicScore.getScenicScore());
        ss.setScenicNum(scenicScore.getScenicNum());
        baseMapper.updateById(scenicScore);
    }

    @Override
    public void deleteScenicScoreById(Long id) {
        baseMapper.deleteById(id);
    }

    @Override
    public ScenicScore getScenicScoreById(Long id) {
        return baseMapper.selectById(id);
    }

    // use "baseMapper" to call jdbc
    // example: baseMapper.insert(entity);
    // example: baseMapper.selectByPage(params);

}
